#include "AbstractEnemy.h"

AbstractEnemy::AbstractEnemy()
{
	IsAlive = true;
	pCurrentState = 0;
	pPlayer = 0;
	Velocity = XMFLOAT3(0.0f,0.0f,0.0f);
	InvunTimer = ENEMY_INVUL_TIME;
	Invunerable = false;
}

AbstractEnemy::~AbstractEnemy()
{
	SafeDelete(EnemyModel);
}

EnemyType AbstractEnemy::GetType()
{
	return Type;
}

void AbstractEnemy::SetType(EnemyType type)
{
	Type = type;
}

int AbstractEnemy::GetDamage()
{
	return Damage;
}

void AbstractEnemy::SetDamage(int damage)
{
	Damage = damage;
}

float AbstractEnemy::GetChaseDistance()
{
	return ChaseDistance;
}

void AbstractEnemy::SetChaseDistance(float distance)
{
	ChaseDistance = distance;
}

float AbstractEnemy::GetAggroRadius()
{
	return AggroRadius;
}

void AbstractEnemy::SetAggroRadius(float radius)
{
	AggroRadius = radius;
}

void AbstractEnemy::AddToBatch(GraphicsInterface* gi)
{
	// Only render the enemy model when it is alive
	if (IsAlive)
	{
		// Render enemy model
		gi->AddModelToBatch(EnemyModel);
	}
}

AABB AbstractEnemy::GetHitBox()
{
	return HitBox;
}

bool AbstractEnemy::GetIsAlive()
{
	return IsAlive;
}

void AbstractEnemy::SetIsAlive(bool alive)
{
	IsAlive = alive;
}

void AbstractEnemy::SetPatrol(std::vector<XMFLOAT3> patrol)
{
	Patrol = patrol;
	EnemyBehaviours.SetPath(patrol);
}

std::vector<XMFLOAT3> AbstractEnemy::GetPatrol()
{
	return Patrol;
}

void AbstractEnemy::SetTarget(XMFLOAT3 target)
{
	Target = target;
}

XMFLOAT3 AbstractEnemy::GetTarget()
{
	return Target;
}
Behaviours* AbstractEnemy::GetBehaviours()
{
	return &EnemyBehaviours;
}

// used to change between states
void AbstractEnemy::ChangeState(State<AbstractEnemy>* pNewState)
{
	//if the pointer is valid
	if(pNewState)
	{
		if(pCurrentState)
		{
			//run exit fucntion on state
			pCurrentState->Exit(this);
		}

		pCurrentState = pNewState;		 //Set state to new state
		pCurrentState->Enter(this);		 //run enter function on state
	}
}

XMFLOAT3 AbstractEnemy::GetPlayerPos()
{
	return pPlayer->GetPosition();
}


XMFLOAT3 AbstractEnemy::GetVelocity()
{
	return Velocity;
}

void AbstractEnemy::SetVelocity(XMFLOAT3 velocity)
{
	Velocity = velocity;
}

XMFLOAT3 AbstractEnemy::GetPosition()
{
	return EnemyModel->GetWorldPosition();
}

int AbstractEnemy::GetHealth()
{
	return Health;
}

void AbstractEnemy::SetHealth(int health)
{
	Health = health;

	if(Health <= 0)
	{
		IsAlive = false;
	}
}

bool AbstractEnemy::GetInvunerable()
{
	return Invunerable;
}

void AbstractEnemy::SetInvunerable(bool invun)
{
	Invunerable = invun;

	if(invun)
	{
		InvunTimer = ENEMY_INVUL_TIME;
	}
}